﻿// //  ********************************************************************************
// //  Copyright (C) 2016 Sebastian Kenter. All rights reserved.
// // 
// //  Name    : MultiServerEngine | MasterServer | MasterServerModule.cs
// //  Created : 2016 - 02 - 16 20:53
// //  Modified: 2016 - 02 - 20 12:33
// //  ********************************************************************************

using Autofac;
using ServerFramework.Implementation.Application;
using ServerFramework.Implementation.Client;
using ServerFramework.Implementation.Handler;
using ServerFramework.Implementation.Handler.Default;
using ServerFramework.Implementation.Handler.Forward;
using ServerFramework.Implementation.Server;
using ServerFramework.Interfaces.Application;
using ServerFramework.Interfaces.Client;
using ServerFramework.Interfaces.Handler;
using ServerFramework.Interfaces.Server;

namespace MasterServer
{
    public class MasterServerModule : Module
    {
        protected override void Load(ContainerBuilder builder)
        {
            base.Load(builder);
            builder.RegisterType<MasterServer>().As<IServerApplication>().SingleInstance();
            builder.RegisterType<ServerPeerFactory>().As<IServerPeerFactory>().SingleInstance();
            builder.RegisterType<ClientPeerFactory>().As<IClientPeerFactory>().SingleInstance();
            builder.RegisterType<ServerPeerRegistry>().As<IServerPeerRegistry<IServerPeer>>().SingleInstance();
            builder.RegisterType<ClientPeerRegistry>().As<IClientPeerRegistry<IClientPeer>>().SingleInstance();
            builder.RegisterType<TelegramHandlerRegistry>().As<ITelegramHandlerRegistry>().SingleInstance();
            builder.RegisterType<DefaultServerRequestHandler>().AsImplementedInterfaces().SingleInstance();
            builder.RegisterType<DefaultServerResponseHandler>().AsImplementedInterfaces().SingleInstance();
            builder.RegisterType<DefaultServerEventHandler>().AsImplementedInterfaces().SingleInstance();
            builder.RegisterType<DefaultClientRequestHandler>().AsImplementedInterfaces().SingleInstance();
            builder.RegisterType<DefaultClientResponseHandler>().AsImplementedInterfaces().SingleInstance();
            builder.RegisterType<DefaultClientEventHandler>().AsImplementedInterfaces().SingleInstance();
            builder.RegisterType<ServerRequestForwardHandler>().AsImplementedInterfaces().SingleInstance();
            builder.RegisterType<ClientRequestForwardHandler>().AsImplementedInterfaces().SingleInstance();
            builder.RegisterAssemblyTypes(ThisAssembly).Where(h => h.Name.EndsWith("Handler")).AsImplementedInterfaces().SingleInstance();
        }
    }
}
